<?php
/**
 * common model file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/11/13
 * Time: 09:49
 */

namespace HiCommon\Model;

class StoreCar extends Base
{

    protected $table = 'store_car';

    protected $guarded = [];

    //public $timestamps = false;

    /**
     * 应该被调整为日期的属性
     *
     * @var array
     */
    protected $dates = [
    ];

    /**
     * 多对一关联门店表
     */
    public function get_shop()
    {
        return $this->belongsTo(Shop::class, 'shop_id', 'id')->select(['id', 'name']);
    }

    /**
     * 一对一关联商品表
     */
    public function get_goods()
    {
        return $this->hasOne(Goods::class, 'id', 'goods_id')->select(['id', 'name', 'status']);
    }

    /**
     * 一对一关联产品表
     */
    public function get_product()
    {
        return $this->hasOne(GoodsProduct::class, 'id', 'goods_product_id')
            ->select(['id', 'goods_specs_id', 'price', 'stock', 'pic'])
            ->with(['specs']);
    }

    /**
     * 一对一关联活动表
     */
    public function get_activity()
    {
        return $this->hasOne(Activity::class, 'id', 'activity_id')
            ->select(['id', 'start_time', 'over_time']);
    }

    /**
     * 扩展信息
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getExtendAttribute()
    {
        $s_created_at = $this->created_at;
        $arr_data = [
            'created_at' => ymd_friendly_date($s_created_at),
        ];

        return $arr_data;
    }


}